package com.qijian.common.utils.poi.handler;

import com.qijian.common.utils.poi.ExcelHandlerAdapter;

import java.math.BigDecimal;

/**
 * 数字处理
 *
 * @author gw
 */
public class NumberMultiplyHandler implements ExcelHandlerAdapter {

    @Override
    public Object format(Object value, String[] args) {
        if (value instanceof Number) {
            if (args.length == 0) {
                return value;
            }
            String result = new BigDecimal(String.valueOf(value)).multiply(new BigDecimal(args[0])).stripTrailingZeros().toPlainString();
            int hasSuffixLength = 2;
            if (args.length >= hasSuffixLength) {
                return result + args[1];
            }
            return result;

        }
        return value;
    }
}
